/*
 * singleton.h
 *
 *  Created on: 2008-9-26
 *      Author: fanliangliang
 */

#ifndef TEST_SINGLETON_H_
#define TEST_SINGLETON_H_

#include "toxic.h"
#include <iostream>

using namespace std;
using namespace toxic; // for singleton

class MySingletonClass : public Singleton<MySingletonClass> {
	friend class Singleton<MySingletonClass>;
protected:
	MySingletonClass() {
		cout << "MySingletonClass()" << endl;
	}

	~MySingletonClass() {
		cout << "~MySingletonClass()" << endl;
	}

public:
	void print() {
		cout << _i << ", ";
		++_i;
	}
private:
	static int _i;
};

int MySingletonClass::_i = 0;


void do_test_singleton() {

	cout << "***** singleton *****" << endl;

	for (int i = 0; i < 5; ++i) {
		MySingletonClass::instance()->print();
	}
	cout << endl;

	// Output:
	// MySingletonClass()
	// 0, 1, 2, 3, 4,
	// ~MySingletonClass()
}

#endif /* TEST_SINGLETON_H_ */
